package com.wsf.demo.mapper;

import com.wsf.demo.entity.TUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //插入user表
    @Insert("insert into TUser(username,password,email,gen_time) values(#{username},#{password},#{email},#{genTime})")
    public int insertUser(TUser user);

    //通过id查询user表
    @Select("select tu_id,username,password,email,gen_time from TUser where tu_id=#{tuId}")
    public TUser selectUserById(int tuId);

    //通过名字查询user表
    @Select("select tu_id,username,password,email,gen_time from TUser where username=#{username}")
    public TUser selectUserByName(String username);

    //姓名模糊查询
    @Select("select tu_id,username,password,email,gen_time from TUser where username like #{username} ")
    public List<TUser> selectUserByNameV2(String username);

    //删除user表
    @Delete("delete from TUser where tu_id=#{tuId}")
    public int deleteUserById(int tuId);

    //删除user角色
    @Delete("delete from TUserRoleRelation where User_id=#{tuId}")
    public int deleteUserRole(int tuId);

    //更新user表
    @Update("update TUser set username=#{username},password=#{password},email=#{email} where tu_id=#{tuId}")
    public int updateUserById(int tuId,String username, String password, String email);

    //查询user角色
    @Select("select Role_id from TUserRoleRelation where User_id=#{tuId}")
    public List<Integer> selectUserRole(int tuId);

    @Insert("insert into TUserRoleRelation(User_id,Role_id) values(#{User_id},#{Role_id})")
    public int insertUserRole(int User_id,int Role_id);

    /*@Select("select tu_id,username,password,email,gen_time from TUser where tu_id=#{tuId}")
    public TUser selectUserBy(int tuId);

    @Select("select tu_id,username,password,email,gen_time from TUser where tu_id=#{tuId}")
    public TUser selectUserById();*/

}
